package com.self.service.util;


import com.self.service.domain.Result;
import com.self.service.enums.ResultEnum;

public class ResultUtil {

    private static <T> Result<T> getResult(Integer code, String msg, T data) {
        Result<T> result = new Result<T>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error() {
        return getResult(ResultEnum.UNKNOW_ERROR.getCode(), ResultEnum.UNKNOW_ERROR.getMsg(), null);
    }

    public static <T> Result<T> success() {
        return getResult(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), null);
    }

    public static <T> Result<T> error(Integer code, String msg) {
        return getResult(code, msg, null);
    }

    public static <T> Result<T> error(ResultEnum resultEnum) {
        return getResult(resultEnum.getCode(), resultEnum.getMsg(), null);
    }

    public static <T> Result<T> error(ResultEnum resultEnum, T data) {
        return getResult(resultEnum.getCode(), resultEnum.getMsg(), data);
    }

    public static <T> Result success(T data) {
        return getResult(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), data);
    }

}
